﻿using System.IO;
using System.Runtime.Serialization.Json;
using System.Text;

namespace SmartMusicBox.Framework.Helper
{
    public class SerializeHelper
    {
        public static T ConvertJsonStringToObject<T>(string jsonString)
        {
            try
            {
                var ser = new DataContractJsonSerializer(typeof(T));
                using (var stream = new MemoryStream(Encoding.Unicode.GetBytes(jsonString)))
                    return (T)ser.ReadObject(stream);
            }
            catch
            {
                return default(T);
            }
        }
    }
}
